package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.view.View;

import com.jwdf.uda.databinding.ItemReplyTitleTabBinding;
import com.jwdf.uda.event.ReplyDetailEvent;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.ReplyDetailItem;
import com.jwdf.uda.utils.EventBusUtil;

/**
 * Created by Administrator on 2016/9/19.
 */
public class ReplyTitleTabViewHolder extends AbsViewHolder<ReplyDetailItem> {

    private ItemReplyTitleTabBinding mBinding;

    public ReplyTitleTabViewHolder(View convertView) {
        super(convertView);
        mBinding = DataBindingUtil.bind(convertView);
    }

    @Override
    protected void onBindView(final ReplyDetailItem item) {
        mBinding.tvTabComment.setText(String.valueOf(item.commentCount));
        mBinding.tvTabPraise.setText(String.valueOf(item.likeCount));

        if (item.currentTab == ReplyDetailItem.ReplyTab.LIKE) {
            showTabPraise();
        } else {
            showTabComment();
        }

        mBinding.flTabComment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.currentTab =ReplyDetailItem.ReplyTab.COMMENT;
                ReplyDetailEvent event = new ReplyDetailEvent(ReplyDetailEvent.EVENT_TAB_COMMENT);
                event.count = item.commentCount;
                EventBusUtil.post(event);
            }
        });
        mBinding.flTabPraise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.currentTab = ReplyDetailItem.ReplyTab.LIKE;
                ReplyDetailEvent event = new ReplyDetailEvent(ReplyDetailEvent.EVENT_TAB_LIKE);
                event.count = item.likeCount;
                EventBusUtil.post(event);
            }
        });
    }

    private void showTabComment() {
        mBinding.tvTabComment.setSelected(true);
        mBinding.tvGuideTitleComment.setSelected(true);
        mBinding.tvGuideTitleLike.setSelected(false);
        mBinding.tvTabPraise.setSelected(false);
        mBinding.vLineComment.setVisibility(View.VISIBLE);
        mBinding.vLinePraise.setVisibility(View.GONE);
    }

    private void showTabPraise() {
        mBinding.tvTabComment.setSelected(false);
        mBinding.tvGuideTitleLike.setSelected(true);
        mBinding.tvGuideTitleComment.setSelected(false);
        mBinding.tvTabPraise.setSelected(true);
        mBinding.vLineComment.setVisibility(View.GONE);
        mBinding.vLinePraise.setVisibility(View.VISIBLE);
    }

}
